package com.phpxiu.app.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.phpxiu.app.api.OnDialogClickListener;
import com.phpxiu.app.kkylive.R;

/**
 * 有确定和取消按钮的交互对话框
 * Created by 吴金洲 on 2016/9/4
 */
public class InteractiveDialog extends Dialog implements View.OnClickListener {
    private TextView titleView, descView;
    private Button okBtn,cancelBtn;
    private OnDialogClickListener mClickListener;

    public InteractiveDialog(Context context) {
        super(context,R.style.interactiveDialog);
        setContentView(R.layout.dialog);
    }

    @Override
    public void setContentView(int layoutResId) {
        if(layoutResId!=0) {
            super.setContentView(layoutResId);
            findViewById(R.id.root_view).setOnClickListener(this);
            titleView = (TextView) findViewById(R.id.dialog_title);
            descView = (TextView) findViewById(R.id.dialog_description);
            cancelBtn = (Button) findViewById(R.id.dialog_cancel);
            cancelBtn.setOnClickListener(this);
            okBtn = (Button) findViewById(R.id.dialog_ok);
            okBtn.setOnClickListener(this);
        }
    }

    /**
     * 设置标题
     * @param title
     */
    public void setTitle(String title){
        if(titleView!=null){
            titleView.setText(title);
        }
    }

    /**
     * 设置对话信息
     * @param desc
     */
    public void setSummary(String desc){
        if(descView!=null){
            descView.setText(desc);
        }
    }

    /**
     * 设置确定按钮标题
     * @param ok
     */
    public void setOkTitle(String ok){
        if(okBtn!=null){
            okBtn.setText(ok);
        }
    }

    /**
     * 设置取消按钮标题
     * @param cancel
     */
    public void setCancelTitle(String cancel){
        if(cancelBtn!=null){
            cancelBtn.setText(cancel);
        }
    }

    @Override
    public void onClick(View v) {
        if(v.getId()== R.id.dialog_ok) {
            if(mClickListener!=null){
                mClickListener.onOk();
            }
        }else{
            if(mClickListener!=null){
                mClickListener.onCancel();
            }
        }
        dismiss();
    }

    /**
     * 设置外部监听
     * @param clickListener
     */
    public void setOnDialogClickListener(OnDialogClickListener clickListener){
        mClickListener=clickListener;
    }

}
